package com.lizanyi.teaFriend.service.impl;

import com.lizanyi.teaFriend.mapper.TeaAdminMapper;
import com.lizanyi.teaFriend.pojo.TeaAdmin;
import com.lizanyi.teaFriend.pojo.TeaAdminExample;
import com.lizanyi.teaFriend.service.AdminService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class AdminServiceimpl implements AdminService {

    @Resource
    @Qualifier("teaAdminMapper")
    private TeaAdminMapper teaAdminMapper;

    @Override
    public TeaAdmin login(String account, String password) throws Exception {
        TeaAdmin   teaAdmin = teaAdminMapper.selectByPrimaryKey(account);
        System.out.println(teaAdmin);
        //匹配密码
        if(null != teaAdmin){
            if(!teaAdmin.getPassword().equals(password)){
                teaAdmin = null;
            }
        }
        return teaAdmin;
    }



    @Override
    public String register(String account ,String password,String password1) throws Exception {
        TeaAdmin teaAdmin=null;
        if(account.equals("")){
            return "empty";
        }
        teaAdmin=teaAdminMapper.selectByPrimaryKey(account);
        if(teaAdmin!=null){
            return "false";
        }else {
            if(password.equals(password1)&& teaAdminMapper.insert(new TeaAdmin(account,password))>0) {
                return "success";
            }else{
                return "fail";
            }

        }

    }

    @Override
    public TeaAdmin selectByAccount(String account) {

        TeaAdmin teaAdmin=teaAdminMapper.selectByPrimaryKey(account);
        return teaAdmin;
    }

    @Override
    public int updateTeaAdmin(String account, String password) {
      int flag=  teaAdminMapper.updateByPrimaryKeySelective(new TeaAdmin(account,password));
      return flag;
    }

    @Override
    public int addTeaAdmin(String account, String password) {
        int flag=teaAdminMapper.insert(new TeaAdmin(account,password));
        return flag;
    }

    @Override
    public int deleteAdmin(String account) {
        int flag=teaAdminMapper.deleteByPrimaryKey(account);
        return flag;
    }


}
